<template>
  <view class="page">
    <!-- 状态栏占位 -->
    <view :style="{ height: statusBarHeight + 'px' }"></view>

    <!-- 导航栏 -->
    <view class="nav-bar">
      <view class="nav-left" @tap="goBack">
        <text class="fa fa-chevron-left fa-gray"></text>
      </view>
      <text class="nav-title">质量检查</text>
      <view class="nav-right" @tap="goToMessages">
        <text class="fa fa-bell-o search-icon fa-gray"></text>
      </view>
    </view>

    <!-- 内容区域 -->
    <scroll-view scroll-y class="content">
      <!-- 搜索框 -->
      <view class="search-section">
        <view class="search-box">
          <text class="fa fa-search search-icon"></text>
          <input
            class="search-input"
            placeholder="搜索检查项目或科室"
            placeholder-style="color: #9ca3af"
            v-model="searchText"
          />
        </view>
      </view>

      <!-- 状态标签 -->
      <view class="tabs-section">
        <view class="tabs">
          <view
            v-for="(tab, index) in tabs"
            :key="index"
            :class="['tab-item', currentTab === index ? 'tab-item-active' : '']"
            @tap="switchTab(index)"
          >
            <text>{{ tab }}</text>
          </view>
        </view>
      </view>

      <!-- 快捷操作 -->
      <view class="quick-actions">
        <view class="card">
          <view class="card-header">
            <text class="card-title">快捷操作</text>
          </view>
          <view class="actions-grid">
            <view class="action-btn action-btn-green" @tap="createCheck">
              <text class="fa fa-plus"></text>
              <text class="action-text">新建检查</text>
            </view>
            <view class="action-btn action-btn-blue" @tap="viewPlan">
              <text class="fa fa-calendar-check-o"></text>
              <text class="action-text">检查计划</text>
            </view>
          </view>
        </view>
      </view>

      <!-- 检查列表 -->
      <view class="check-list">
        <!-- 检查项目1 - 待检查 -->
        <view class="check-card">
          <view class="check-content">
            <view class="check-icon check-icon-orange">
              <text class="fa fa-clipboard fa-orange"></text>
            </view>
            <view class="check-info">
              <text class="check-title">ICU病房护理质量专项检查</text>
              <text class="check-meta">检查类型：专项检查</text>
              <text class="check-time">计划时间：2025.01.22 09:00</text>
              <text class="check-dept">检查科室：ICU</text>
              <view class="check-tags">
                <view class="tag tag-orange">
                  <text>待检查</text>
                </view>
                <text class="check-inspector">检查员：李主任</text>
              </view>
            </view>
            <view class="check-side">
              <text class="check-level check-level-red">一级质控</text>
              <view class="check-action" @tap="viewDetail(1)">
                <text class="fa fa-eye"></text>
              </view>
            </view>
          </view>
        </view>

        <!-- 检查项目2 - 检查中 -->
        <view class="check-card">
          <view class="check-content">
            <view class="check-icon check-icon-blue">
              <text class="fa fa-search fa-blue"></text>
            </view>
            <view class="check-info">
              <text class="check-title">医疗器械消毒规范执行情况检查</text>
              <text class="check-meta">检查类型：常规检查</text>
              <text class="check-time">开始时间：2025.01.20 14:00</text>
              <text class="check-dept">检查科室：消毒供应中心</text>
              <view class="check-tags">
                <view class="tag tag-blue">
                  <text>检查中</text>
                </view>
                <text class="check-inspector">检查员：王主任</text>
              </view>
              <view class="progress-wrapper">
                <view class="progress-bar">
                  <view class="progress-fill" style="width: 65%"></view>
                </view>
                <text class="progress-text">65%</text>
              </view>
            </view>
            <view class="check-side">
              <text class="check-level check-level-yellow">二级质控</text>
              <view class="check-action" @tap="editCheck(2)">
                <text class="fa fa-edit"></text>
              </view>
            </view>
          </view>
        </view>

        <!-- 检查项目3 - 已完成 -->
        <view class="check-card">
          <view class="check-content">
            <view class="check-icon check-icon-green">
              <text class="fa fa-check-square fa-green"></text>
            </view>
            <view class="check-info">
              <text class="check-title">急诊科抢救设备维护检查</text>
              <text class="check-meta">检查类型：设备检查</text>
              <text class="check-time">完成时间：2025.01.18 16:30</text>
              <text class="check-dept">检查科室：急诊科</text>
              <view class="check-tags">
                <view class="tag tag-green">
                  <text>已完成</text>
                </view>
                <text class="check-inspector">检查员：陈主任</text>
              </view>
              <view class="result-info">
                <text class="result-label">检查结果：</text>
                <view class="result-tag result-tag-green">
                  <text>合格</text>
                </view>
                <text class="result-issues">问题数：2个</text>
              </view>
            </view>
            <view class="check-side">
              <text class="check-level check-level-green">三级质控</text>
              <view class="check-action" @tap="viewReport(3)">
                <text class="fa fa-file-text-o"></text>
              </view>
            </view>
          </view>
        </view>

        <!-- 检查项目4 - 已完成有问题 -->
        <view class="check-card">
          <view class="check-content">
            <view class="check-icon check-icon-red">
              <text class="fa fa-warning fa-red"></text>
            </view>
            <view class="check-info">
              <text class="check-title">外科手术室无菌操作规范检查</text>
              <text class="check-meta">检查类型：专项检查</text>
              <text class="check-time">完成时间：2025.01.17 11:45</text>
              <text class="check-dept">检查科室：外科手术室</text>
              <view class="check-tags">
                <view class="tag tag-red">
                  <text>需整改</text>
                </view>
                <text class="check-inspector">检查员：张主任</text>
              </view>
              <view class="result-info">
                <text class="result-label">检查结果：</text>
                <view class="result-tag result-tag-red">
                  <text>不合格</text>
                </view>
                <text class="result-issues result-issues-red">问题数：5个</text>
              </view>
            </view>
            <view class="check-side">
              <text class="check-level check-level-red">一级质控</text>
              <view class="check-action check-action-red" @tap="viewIssues(4)">
                <text class="fa fa-info"></text>
              </view>
            </view>
          </view>
        </view>
      </view>
    </scroll-view>

    <!-- 底部导航栏 -->
    <view class="tabbar">
      <view class="tab-item" @tap="goToHome">
        <text class="fa fa-home"></text>
        <text class="tab-label">首页</text>
      </view>
      <view class="tab-item tab-item-active">
        <text class="fa fa-cog"></text>
        <text class="tab-label">工作台</text>
      </view>
      <view class="tab-item" @tap="goToProfile">
        <text class="fa fa-user"></text>
        <text class="tab-label">我的</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      statusBarHeight: 0,
      searchText: "",
      currentTab: 0,
      tabs: ["全部", "待检查", "检查中", "已完成"],
    };
  },
  onLoad() {
    this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight || 0;
  },
  methods: {
    goBack() {
      uni.navigateBack();
    },
    goToMessages() {
      uni.navigateTo({
        url: "/pages/messages",
      });
    },
    switchTab(index) {
      this.currentTab = index;
    },
    createCheck() {
      uni.showToast({
        title: "新建检查",
        icon: "none",
      });
    },
    viewPlan() {
      uni.showToast({
        title: "查看检查计划",
        icon: "none",
      });
    },
    viewDetail(id) {
      uni.showToast({
        title: "查看详情",
        icon: "none",
      });
    },
    editCheck(id) {
      uni.showToast({
        title: "继续检查",
        icon: "none",
      });
    },
    viewReport(id) {
      uni.showToast({
        title: "查看报告",
        icon: "none",
      });
    },
    viewIssues(id) {
      uni.showToast({
        title: "查看问题",
        icon: "none",
      });
    },
    goToHome() {
      uni.navigateTo({
        url: "/pages/home",
      });
    },
    goToProfile() {
      uni.navigateTo({
        url: "/pages/profile",
      });
    },
  },
};
</script>

<style scoped>
.page {
  min-height: 100vh;
  background: linear-gradient(to bottom right, #f9fafb, #eff6ff);
  display: flex;
  flex-direction: column;
}

.nav-bar {
  height: 88rpx;
  background: #fff;
  border-bottom: 1rpx solid #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.nav-left {
  position: absolute;
  left: 32rpx;
}

.nav-title {
  font-size: 34rpx;
  font-weight: 600;
  color: #111827;
}

.nav-right {
  position: absolute;
  right: 32rpx;
  font-size: 36rpx;
  color: #6b7280;
}

.content {
  flex: 1;
}

.search-section {
  padding: 24rpx 32rpx;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 16rpx;
  background: #fff;
  border-radius: 24rpx;
  padding: 16rpx 24rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  border: 1rpx solid #f3f4f6;
}

.search-icon {
  font-size: 32rpx;
  color: #9ca3af;
}

.search-input {
  flex: 1;
  font-size: 28rpx;
  color: #111827;
}

.tabs-section {
  padding: 0 32rpx;
}

.tabs {
  display: flex;
  background: #fff;
  border-radius: 24rpx 24rpx 0 0;
  border-bottom: 1rpx solid #e5e7eb;
}

.tab-item {
  flex: 1;
  padding: 24rpx 0;
  text-align: center;
  font-size: 28rpx;
  color: #6b7280;
  position: relative;
}

.tab-item-active {
  color: #2563eb;
  font-weight: 500;
}

.tab-item-active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60rpx;
  height: 4rpx;
  background: #2563eb;
  border-radius: 2rpx;
}

.quick-actions {
  padding: 0 32rpx;
  margin-top: 24rpx;
}

.card {
  background: #fff;
  border-radius: 32rpx;
  padding: 32rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  border: 1rpx solid #f3f4f6;
}

.card-header {
  margin-bottom: 24rpx;
}

.card-title {
  font-size: 32rpx;
  font-weight: 600;
  color: #111827;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24rpx;
}

.action-btn {
  border-radius: 24rpx;
  padding: 24rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16rpx;
  color: #fff;
  font-weight: 500;
}

.action-btn-green {
  background: linear-gradient(to right, #22c55e, #10b981);
}

.action-btn-blue {
  background: linear-gradient(to right, #3b82f6, #6366f1);
}

.check-list {
  padding: 24rpx 32rpx;
  display: flex;
  flex-direction: column;
  gap: 24rpx;
}

.check-card {
  background: #fff;
  border-radius: 32rpx;
  padding: 32rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  border: 1rpx solid #f3f4f6;
}

.check-content {
  display: flex;
  gap: 24rpx;
}

.check-icon {
  width: 96rpx;
  height: 96rpx;
  border-radius: 24rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40rpx;
  flex-shrink: 0;
}

.check-icon-orange {
  background: #fed7aa;
}

.check-icon-blue {
  background: #bfdbfe;
}

.check-icon-green {
  background: #bbf7d0;
}

.check-icon-red {
  background: #fecaca;
}

.check-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8rpx;
}

.check-title {
  font-size: 28rpx;
  font-weight: 600;
  color: #111827;
}

.check-meta,
.check-time,
.check-dept {
  font-size: 24rpx;
  color: #6b7280;
}

.check-tags {
  display: flex;
  align-items: center;
  gap: 16rpx;
  margin-top: 8rpx;
}

.tag {
  padding: 8rpx 16rpx;
  border-radius: 16rpx;
  font-size: 24rpx;
  font-weight: 500;
}

.tag-orange {
  background: #fed7aa;
  color: #c2410c;
}

.tag-blue {
  background: #bfdbfe;
  color: #1e40af;
}

.tag-green {
  background: #bbf7d0;
  color: #15803d;
}

.tag-red {
  background: #fecaca;
  color: #b91c1c;
}

.check-inspector {
  font-size: 24rpx;
  color: #6b7280;
}

.check-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 16rpx;
}

.check-level {
  font-size: 24rpx;
  font-weight: 500;
}

.check-level-red {
  color: #dc2626;
}

.check-level-yellow {
  color: #ca8a04;
}

.check-level-green {
  color: #16a34a;
}

.check-action {
  font-size: 28rpx;
  color: #2563eb;
}

.check-action-red {
  color: #dc2626;
}

.progress-wrapper {
  display: flex;
  align-items: center;
  gap: 16rpx;
  margin-top: 16rpx;
}

.progress-bar {
  flex: 1;
  height: 12rpx;
  background: #e5e7eb;
  border-radius: 999rpx;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(to right, #3b82f6, #6366f1);
  border-radius: 999rpx;
}

.progress-text {
  font-size: 24rpx;
  font-weight: 500;
  color: #4b5563;
}

.result-info {
  display: flex;
  align-items: center;
  gap: 12rpx;
  margin-top: 16rpx;
}

.result-label {
  font-size: 24rpx;
  color: #6b7280;
}

.result-tag {
  padding: 4rpx 12rpx;
  border-radius: 8rpx;
  font-size: 24rpx;
  font-weight: 500;
}

.result-tag-green {
  background: #dcfce7;
  color: #15803d;
}

.result-tag-red {
  background: #fee2e2;
  color: #b91c1c;
}

.result-issues {
  font-size: 24rpx;
  color: #6b7280;
}

.result-issues-red {
  color: #dc2626;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120rpx;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(20rpx);
  border-top: 1rpx solid #f3f4f6;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8rpx;
  color: #6b7280;
}

.tab-item-active {
  color: #2563eb;
}

.tab-icon {
  font-size: 36rpx;
}

.tab-label {
  font-size: 20rpx;
}

.tab-item-active .tab-label {
  font-weight: 500;
}
</style>

